package ofc4j.util;

import ofc4j.model.elements.BarChart;
import ofc4j.model.elements.FilledBarChart;
import ofc4j.model.elements.SketchBarChart;

import com.thoughtworks.xstream.converters.MarshallingContext;
import com.thoughtworks.xstream.io.path.PathTrackingWriter;

public class BarConverter extends ConverterBase<BarChart.Bar> {
    @Override
    public void convert(BarChart.Bar b, PathTrackingWriter writer, MarshallingContext mc) {
        writeNode(writer, "top", b.getTop());
        writeNode(writer, "bottom", b.getBottom());
        writeNode(writer, "colour", b.getColour());
        writeNode(writer, "tip", b.getTooltip());
        if (b instanceof FilledBarChart.Bar) {
            writeNode(writer, "outline-colour", ((FilledBarChart.Bar)b).getOutlineColour());
        }
        if (b instanceof SketchBarChart.Bar) {
            writeNode(writer, "offset", ((SketchBarChart.Bar)b).getFunFactor());
        }
    }
    
	@Override
	@SuppressWarnings("unchecked")
	public boolean canConvert(Class clazz) {
		return BarChart.Bar.class.isAssignableFrom(clazz);
	}
}
